<?php

	class RTemplate
	{
		var $templates = array('index' => 'index.tmpl', 'advert' => 'simple.tmpl');
		
		var $defaulttemplate = 'blank.tmpl';
		
		var $curtemplate = NULL;
		
		private $replacement = array();
		
		function __construct($modulename)
		{
			$this->curtemplate = isset($this->templates[$modulename])?$this->templates[$modulename]:$this->defaulttemplate;
		}
		
		function getTemplate($modulename = '')
		{
			static $instance;
			if ($instance) return $instance;
			
			return $instance = new RTemplate($modulename);
		}
		
		function registerVar($name, $value)
		{
			$this->replacement[$name] = $value;

		}
		
		function render()
		{
			
			$matches = array();
			$template = file_get_contents(BP.DS.'templates'.DS.$this->curtemplate);
			preg_match_all('/\{rtag\s+name=([a-zA-Z]+)\s+type=([a-zA-Z]+)\s+\}/', $template, $matches);
			$template = str_replace('{content}', $this->replacement['content'], $template);
			echo $template;
		}
		
	}